
import { db } from './database/DataBase';
import { InnerProtocol } from './proto/innerMsg';
import { BridgeServer } from './server/bridgeserver/BridgeServer';
import { GameServer } from './server/gameserver/GameServer';
import { LobbyServer } from './server/lobbyserver/LobbyServer';
import { InnerServer } from './socket/ClientServer';

const oldLog = console.log;
console.log = function (message?: any, ...optionalParams: any[]) {
    oldLog.call(console, new Date().toLocaleString() + '  ' + message, ...optionalParams)
}

console.log('*********node js start');

process.on('uncaughtException', err => {
    console.error(new Date().toLocaleString() + ' 有一个未捕获的错误', err)
    // process.exit(1) //强制性的（根据 Node.js 文档）
});

(async function () {
    await db.initDB()
    new BridgeServer().startServer(8997)
    const lobbyserver = new LobbyServer(InnerServer.LOBBY)
    lobbyserver.startServer(8998)
    await lobbyserver.startBridge('127.0.0.1', 8997)
    const gameerver = new GameServer(InnerServer.GAME)
    gameerver.startServer(8999)
    await gameerver.startBridge('127.0.0.1', 8997)
}())










